home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 289_01.zip / BLDFA.C < prev    next >
Text File  |  1993-04-26  |  3KB  |  123 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "othello.h"
  5.  
  6.  
  7.  
  8. void main (void)
  9. {
  10. fa_type fa_ndx_tbl [8][8];
  11. register int r;
  12. register int c;
  13. unsigned char next_fa_bit;
  14.  
  15.  
  16. /*-------------------------------------
  17. Initialize some variables. Clear the
  18. table to all zeroes.
  19. -------------------------------------*/
  20.  
  21. next_fa_bit = 1;
  22. memset (fa_ndx_tbl, 0, sizeof (fa_ndx_tbl));
  23.  
  24.  
  25. /*-------------------------------------
  26. Initialize the horizontal index for all
  27. cells in the fa index table.
  28. -------------------------------------*/
  29.  
  30. for (r = 0; r < 8; r++, next_fa_bit++)
  31.   for (c = 0; c < 8; c++)
  32.     fa_ndx_tbl [r][c][H_NDX] = next_fa_bit;
  33.  
  34.  
  35. /*-------------------------------------
  36. Initialize the vertical index for all
  37. cells in the fa index table.
  38. -------------------------------------*/
  39.  
  40. for (c = 0; c < 8; c++, next_fa_bit++)
  41.   for (r = 0; r < 8; r++)
  42.     fa_ndx_tbl [r][c][V_NDX] = next_fa_bit;
  43.  
  44.  
  45. /*-------------------------------------
  46. Initialize the positive slope diagonals
  47. (forward diagonal) starting from the
  48. left and bottom edges and moving up.
  49. This is more tricky, since we have to
  50. move diagonally.
  51. -------------------------------------*/
  52.  
  53. for (r = 2; r < 8; r++, next_fa_bit++)
  54.   {
  55.   int r2;    /* temp row */
  56.  
  57.   r2 = r;
  58.   for (c = 0; (c < 8) && (r2 >= 0); c++, r2--)
  59.     fa_ndx_tbl [r2][c][FD_NDX] = next_fa_bit;
  60.   }
  61.  
  62. for (c = 0; c < 6; c++, next_fa_bit++)
  63.   {
  64.   int c2;    /* temp column */
  65.  
  66.   c2 = c;
  67.   for (r = 7; (r >= 0) && (c2 < 8); r--, c2++)
  68.     fa_ndx_tbl [r][c2][FD_NDX] = next_fa_bit;
  69.   }
  70.  
  71.  
  72. /*-------------------------------------
  73. Initialize the negative slope diagonals
  74. (backward diagonal) starting from the
  75. top and left edges and moving down.
  76. This uses the same method to move
  77. diagonally as in the positive diags.
  78. -------------------------------------*/
  79.  
  80. for (c = 0; c < 6; c++, next_fa_bit++)
  81.   {
  82.   int c2;    /* temp column */
  83.  
  84.   c2 = c;
  85.   for (r = 0; (r < 8) && (c2 < 8); r++, c2++)
  86.     fa_ndx_tbl [r][c2][BD_NDX] = next_fa_bit;
  87.   }
  88.  
  89. for (r = 1; r < 6; r++, next_fa_bit++)
  90.   {
  91.   int r2;    /* temp row */
  92.  
  93.   r2 = r;
  94.   for (c = 0; (c < 8) && (r2 < 8); c++, r2++)
  95.     fa_ndx_tbl [r2][c][BD_NDX] = next_fa_bit;
  96.   }
  97.  
  98.  
  99. /*-------------------------------------
  100. Now, print it out!
  101. -------------------------------------*/
  102.  
  103. for (r=0; r<8; r++)
  104.   {
  105.   for (c=0; c<8; c++)
  106.     {
  107.     printf ("    { %2d, %2d, %2d, %2d },\t\t/* %d,%d */\n",
  108.     fa_ndx_tbl [r][c][BD_NDX],
  109.     fa_ndx_tbl [r][c][FD_NDX],
  110.     fa_ndx_tbl [r][c][H_NDX],
  111.     fa_ndx_tbl [r][c][V_NDX],
  112.     r, c);
  113.     }
  114.   printf ("\n");
  115.   }
  116.  
  117. }
  118.  
  119.  
  120. /*-----------------------------------------------------------------------------
  121. -----------------------------------------------------------------------------*/
  122.  
  123.